package com.zhdl.modules.common.warn.service;

import com.zhdl.modules.common.warn.entity.WarnRecords;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class RunWarnService {
    @Resource
    WarnRecordsService warnHistoryService;
    public List<WarnRecords> currentWarnList = new ArrayList<>();
    public void addNewWarnService(WarnRecords warning){
        currentWarnList.add(warning);
    }
    public void addNewWarnService(String desc,int code){
        WarnRecords warning = new WarnRecords(code,desc);
        currentWarnList.add(warning);
    }
    public void resetWarn(int code){
        WarnRecords warning = null;
        for (WarnRecords WarnRecords : currentWarnList) {
            if (code ==WarnRecords.getWarnType()){
                warning = WarnRecords;
                break;
            }
        }
        if (warning!=null){
            currentWarnList.remove(warning);
            warnHistoryService.saveManyWarn(new WarnRecords(code,warning.getWarnInfo()));
        }
    }
    public void resetAll(){
        warnHistoryService.saveManyWarn(currentWarnList);
        currentWarnList.clear();
    }
}
